package mess;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

public class LeeCode_02_2 {
    public static void main(String[] args) {
        LinkedList<Integer> l1 = new LinkedList<>();
        l1.add(2);
        l1.add(4);
        l1.add(3);
        LinkedList<Integer> l2 = new LinkedList<>();
        l2.add(5);
        l2.add(6);
        l2.add(4);
        System.out.println(addTwoNumbers(l1, l2));
        Set<String> set = new HashSet<>();
        
    }

    private static LinkedList<Integer> addTwoNumbers(LinkedList<Integer> l1, LinkedList<Integer> l2) {
        int num1 = 0;
        int num2 = 0;
        int temp = 1;
        for (int i = 1; i < l1.size(); i++) {
            temp *= 10;
        }
        for (Integer num : l1) {
            num1 += num * temp;
            temp /= 10;
        }
        temp = 1;
        for (int i = 1; i < l2.size(); i++) {
            temp *= 10;
        }
        for (Integer num : l2) {
            num2 += num * temp;
            temp /= 10;
        }
        int result = num1 + num2;
        LinkedList<Integer> resultList = new LinkedList<>();
        while (result != 0){
            int single = result % 10;
            resultList.add(single);
            result /= 10;
        }
        return resultList;
    }
}
